<?php

namespace app\admin\controller;

use think\facade\Request;
use app\common\Common;
use app\admin\service\VideoService;

// 推荐指定发布者的其他短剧设置
class Other extends Base
{
    private $service;

    public function __construct(VideoService $service)
    {
        parent::__construct();
        $this->service = $service;
    }

    // 渲染列表页面
    public function index()
    {
        return view();
    }

    // 渲染详情页面
    public function info()
    {
        return view();
    }

    // 添加指定发布者的其他短剧
    public function add()
    {
        $params = Request::param();

        try {
            validate(\app\admin\validate\Other::class)->scene('add')->check($params);
        } catch (\Exception $e) {
            return Common::fail($e->getError());
        }

        $result = $this->service->editPublisherOtherVideo($params);

        if (!$result) {
            return Common::fail();
        }

        return Common::success();
    }

    // 发布者推荐的短剧列表
    public function list()
    {
        $params = Request::param();

        $data = $this->service->getPublisherOtherVideoList($params);

        return Common::success($data);
    }

    // 修改指定发布者的其他短剧
    public function edit()
    {
        $params = Request::param();

        try {
            validate(\app\admin\validate\Other::class)->scene('edit')->check($params);
        } catch (\Exception $e) {
            return Common::fail($e->getError());
        }

        $result = $this->service->editPublisherOtherVideo($params);

        if (!$result) {
            return Common::fail();
        }

        return Common::success();
    }

    // 指定发布者的短剧详情
    public function detail()
    {
        $params = Request::param();

        try {
            validate(\app\admin\validate\Other::class)->scene('detail')->check($params);
        } catch (\Exception $e) {
            return Common::fail($e->getError());
        }

        $data = $this->service->getPublisherOtherVideoDetail($params['id']);

        return Common::success($data);
    }

    // 删除发布者的其他推荐短剧
    public function delete()
    {
        $params = Request::param();

        try {
            validate(\app\admin\validate\Other::class)->scene('delete')->check($params);
        } catch (\Exception $e) {
            return Common::fail($e->getError());
        }

        $result = $this->service->deletePublisherOtherVideo($params['id']);

        if (!$result) {
            return Common::fail();
        }

        return Common::success();
    }

}